class AdherentsController < ApplicationController
  # GET /adherents
  # GET /adherents.xml
  
  auto_complete_for :adherent, :nom
  
  def index
    @adherents = Adherent.paginate(:page => params[:page], :per_page => 20, :conditions => ["nom like ? ", "%" + "#{params[:search]}" + "%"] )
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @adherents }
    end
  end

  # GET /adherents/1
  # GET /adherents/1.xml
  def show
    @adherent = Adherent.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @adherent }
    end
  end

  # GET /adherents/new
  # GET /adherents/new.xml
  def new
    @adherent = Adherent.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @adherent }
    end
  end

  # GET /adherents/1/edit
  def edit
    @adherent = Adherent.find(params[:id])
  end

  # POST /adherents
  # POST /adherents.xml
  def create
    @adherent = Adherent.new(params[:adherent])

    respond_to do |format|
      if @adherent.save
        flash[:notice] = "L'adhérent a été correctement créer."
        format.html { redirect_to(@adherent) }
        format.xml  { render :xml => @adherent, :status => :created, :location => @adherent }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @adherent.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /adherents/1
  # PUT /adherents/1.xml
  def update
    @adherent = Adherent.find(params[:id])

    respond_to do |format|
      if @adherent.update_attributes(params[:adherent])
        flash[:notice] = "L'adhérent a été correctement mis à jour."
        format.html { redirect_to(@adherent) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @adherent.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /adherents/1
  # DELETE /adherents/1.xml
  def destroy
    @adherent = Adherent.find(params[:id])
    @adherent.destroy
    flash[:notice] = "L'adherent a été correctement détruit."
    
    respond_to do |format|
      format.html { redirect_to(adherents_url) }
      format.xml  { head :ok }
    end
  end
  
end
